package main

import (
	"log"
	"math/rand"
	"runtime"
	_ "studygo/init" //为了引入 log
	"time"
)

//init
func init() {
	rand.Seed(time.Now().UnixNano())
	log.SetPrefix("TRACE: ")
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
}
func main() {
	go func() {
		for i := 0; i < 10; i++ {
			if i == 5 {
				//停止协程
				runtime.Goexit()
			}
			log.Println("go ", i)
			time.Sleep(500 * time.Millisecond)
		}
	}()

	for i := 0; i < 10; i++ {
		log.Println("main ", i)
		time.Sleep(500 * time.Millisecond)
	}
}
